﻿<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 4.3.2 or newer
 *
 * @package		CodeIgniter
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2008 - 2010, EllisLab, Inc.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * CodeIgniter Application Controller Class
 *
 * This class object is the super class that every library in
 * CodeIgniter will be assigned to.
 *
 * @package		CodeIgniter
 * @subpackage	Libraries
 * @category	Libraries
 * @author		ExpressionEngine Dev Team
 * @link		http://codeigniter.com/user_guide/general/controllers.html
 */
class Controller extends CI_Base {

	var $_ci_scaffolding	= FALSE;
	var $_ci_scaff_table	= FALSE;
	
	private $controler_name;
	/**
	 * Constructor
	 *
	 * Calls the initialize() function
	 */
	function Controller($name = "")
	{	
		parent::CI_Base();
		$this->_ci_initialize();
		log_message('debug', "Controller Class Initialized");
		
		$this->controler_name = $name;
	}

	// --------------------------------------------------------------------

	/**
	 * Initialize
	 *
	 * Assigns all the bases classes loaded by the front controller to
	 * variables in this class.  Also calls the autoload routine.
	 *
	 * @access	private
	 * @return	void
	 */
	function _ci_initialize()
	{
		// Assign all the class objects that were instantiated by the
		// front controller to local class variables so that CI can be
		// run as one big super object.
		$classes = array(
							'config'	=> 'Config',
							'input'		=> 'Input',
							'benchmark'	=> 'Benchmark',
							'uri'		=> 'URI',
							'output'	=> 'Output',
							'lang'		=> 'Language',
							'router'	=> 'Router'
							);
		
		foreach ($classes as $var => $class)
		{
			$this->$var =& load_class($class);
		}

		// In PHP 5 the Loader class is run as a discreet
		// class.  In PHP 4 it extends the Controller
		if (floor(phpversion()) >= 5)
		{
			$this->load =& load_class('Loader');
			$this->load->_ci_autoloader();
		}
		else
		{
			$this->_ci_autoloader();
			
			// sync up the objects since PHP4 was working from a copy
			foreach (array_keys(get_object_vars($this)) as $attribute)
			{
				if (is_object($this->$attribute))
				{
					$this->load->$attribute =& $this->$attribute;
				}
			}
		}
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Run Scaffolding
	 *
	 * @access	private
	 * @return	void
	 */	
	function _ci_scaffolding()
	{
		if ($this->_ci_scaffolding === FALSE OR $this->_ci_scaff_table === FALSE)
		{
			show_404('Scaffolding unavailable');
		}
		
		$method = ( ! in_array($this->uri->segment(3), array('add', 'insert', 'edit', 'update', 'view', 'delete', 'do_delete'), TRUE)) ? 'view' : $this->uri->segment(3);
		
		require_once(BASEPATH.'scaffolding/Scaffolding'.EXT);
		$scaff = new Scaffolding($this->_ci_scaff_table);
		$scaff->$method();
	}


	function get_controller_name(){
		return $this->controler_name;
	}
	
	function write_sidebar($topic){
		$topic = implode(" OR ", explode(" ", $topic));
						
		$form_url = base_url()."contacto/process"; 		
		$content ="<ul id='sidebar'  class='lheader'>".
		/*
		"<li>
			<h2 class='ui-accordion-header ui-state-active'>Feedback</h2>".
			form_open($form_url , 'onsubmit="return false;" id="contact"').
			"<div class='comment' style='text-align:center; padding: 10px 0px'>".
				"<p>¿Que pensas del sitio? ¿Es util? ¿Que podemos mejorar?</p><h4>Tu opinion es muy importante para nosotros.</h4>".			
			"</div>".
			"<div>
				<label for='username'>*Nombre:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>				
				<input type='text' name='username' id='username' style='width:60%'/>				
			</div>
			<div>
				<label for='email'>*Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>				
				<input type='text' name='email' id='email' style='width:60%'/>				
			</div>
			<div>
				<label for='comment'>*Comentario:</label>								
				<textarea rows='5' cols='27' name='comment' id='comment'></textarea>				
			</div>".
			"<div class='comment>".				
				"<input class='submit' type='submit' value='Enviar!' />".
				"<span>*Campos obligatorios</span>".
			"</div>".
			"<span id='success' class='ui-state-highlight' style='display:none'></span>
			</form>
		</li>
		*/
			"<li class='figcaption'>
				<script type='text/javascript'><!--
				google_ad_client = 'ca-pub-2113662635661393';
				/* Sidebar */
				google_ad_slot = '5693718012';
				google_ad_width = 336;
				google_ad_height = 280;
				//-->
				</script>
				<script type='text/javascript'
				src='http://pagead2.googlesyndication.com/pagead/show_ads.js'>
				</script>		
			</li>
			
			<!-- ML BANNER-->
			<li  style='padding-top:5px; padding-left:30px'>
				<!--
				<iframe src='http://pmssrv.mercadolibre.com.ar/jm/PmsSrv?tool=6126531&creativity=469812&new=Y&ovr=Y' 
				width='300' height='250' scrolling='no' frameborder='0' marginheight='0' marginwidth='0'>				
				</iframe>
				-->
				<!-- SMART AD-->
				<iframe src='http://smartad.mercadolibre.com.ar/jm/SmartAd?tool=6130020&creativity=32401&new=Y&ovr=N&bgcol=FFFFFF&brdcol=000000&txtcol=006600&lnkcol=0000FF&hvrcol=FF0000&prccol=FF0000&word=vehiculos&word=ropa&word=juguetes&site=MLA' 
				width='300' height='250' scrolling='no' frameborder='0' marginheight='0' marginwidth='0'>
				</iframe>
			</li>
			
			<li id='noticias' title='Punta Alta, Noticias' class='menu twitter_feed'>
				<h2 class='ui-accordion-header ui-state-default ui-corner-top'>Noticias</h2>
				<script>			
				new TWTR.Widget({
				  version: 2,
				  type: 'search',
				  search: 'conocepunta OR ".$topic." OR from:lanuevaweb OR from:bahiadigital OR from:tn_todonoticias OR from:c5n OR from:elrosalenio OR from:labrujula24 OR from:perfildiario OR from:infobae OR #bahiablanca OR #puntaalta',
				  //search: '#bahiablanca',
				  interval: 20000,
				  title: '',
				  subject: '',
				  width: 'auto',
				  height: '500',
				  theme: {
					shell: {
					  background: 'none',
					  color: '#000000'
					},
					tweets: {
					  background: 'none',
					  color: '#000000',
					  links: '#DC5751'
					}
				  },
				  features: {
					scrollbar: true,
					loop: true,
					live: true,
					hashtags: true,
					timestamp: true,
					avatars: true,
					behavior: 'default'
				  }
				}).render().start();
				</script>
			</li>
		</ul>";
			
		return $content;
	}
	
	function write_custom_content($places){		
		$content = "<div id='events' class='lheader'>";
		$counter = 1;

		foreach ($places as $place){
			if(($counter % 15) != 0){
				$face_like = '<span>
								<iframe src="http://www.facebook.com/plugins/like.php?href='.base_url().$this->get_controller_name().'/nombre/'.$place['name'].'&amp;layout=button_count&amp;show-faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;locale=es_LA" frameborder="0" scrolling="no" style="vertical-align: middle; border: medium none; overflow: hidden; width: 100px; height: 21px;" allowtransparency="true"></iframe>
							 </span>';
			$name_replaced = str_replace("-", " ", $place['name']);		
			
			//$image = ($place->img == "") ? "<figure><img title='".$name_replaced."' alt='".$name_replaced."' src='".base_url().$place->icon."'></figure>" : "<figure><img title='".$name_replaced."' alt='".$name_replaced."' src='".$place->img."'></figure>";
			$image = "<figure><img title='".$name_replaced."' alt='".$name_replaced."' src='".$place['img']."'></figure>";
			$content .= "<article class='inline box post' title='".$name_replaced."'>".
      	                    "<div class='screenshot vintage'>".
      	                    	$image.      	                    	
              					"<p class='hover'>".
       		       					"<a class='hoverButton inline' href='".base_url().$this->get_controller_name()."/nombre/".$place['name']."'>Mas</a>".
              						//"<a class='hoverButton inline geoButton' id='".$place['name']."' onclick='locate(\"".$this->get_controller_name()."\", this.id);'>Mapa</a>".	NO MORE MAP BUTTON
              					"</p>".
      	                    "</div>".
              				"<div class='figcaption'>".
              					//"<p>".str_pad(substr($name_replaced,0,20),23,"...")."</p>".	                    	
								"<p>$name_replaced</p>".
              				"</div>".     
              				"<div class='fb_like'>$face_like</div>".   				
                          "</article>";
		}else{
			if(($counter % 15) == 0){
				//post Google Ad
				$content .= "<article class='inline box post'>".
								"<div class='screenshot vintage'>".
									"<figure>".										
										"<script type='text/javascript'><!--
											google_ad_client = 'ca-pub-2113662635661393';
											/* custom_content */
											google_ad_slot = '7944803694';
											google_ad_width = 170;
											google_ad_height = 200;
											//-->
										</script>
										<script type='text/javascript'
											src='http://pagead2.googlesyndication.com/pagead/show_ads.js'>
										</script>".								
									"</figure>".
									"<p class='hover'>".
									"</p>".
								"</div>".
							"</article>";
			}else{
				//post eco banner
				$content .= "<article class='inline box post'>".
							"<div class='screenshot vintage'>".
								"<figure>".
									"<img src='http://www.greenpeace.org/argentina/Global/argentina/graphics/probono/artico/250x250.jpg' width='140' height='210' border='0' />".
								"</figure>".
								"<p class='hover'>".
									"<a class='hoverButton inline' target='_blank' href='http://www.greenpeace.org.ar/cyberacciones/index.php?cyberaccion=5122&referer=baners_webprobono_artico'>Mas</a>".
								"</p>".
							"</div>".
							"<div class='figcaption'>".
								"<p>Campa&ntilde;a Greenpeace</p>".
							"</div>".
						"</article>";				
			}
		}
		$counter ++;
		}
				
		$content .= "</div>";
		return $content;
	}
	
	function write_specific_item($marker){			
		$content = "";
		$marker_name = str_replace("-", " ", $marker['name']);
		$url  = "www.conocepunta.com.ar/".$this->get_controller_name()."/nombre/".$marker['name'];			
		
		//$date = ($marker["fecha"] != "")?date("M D j, G:i",strtotime($marker["fecha"]))."HS: ": ""; 
		//social widgets---------------------
		$fb   = "<div class='fb_like'><iframe src='http://www.facebook.com/plugins/like.php?href=".$url."&amp;layout=button_count&amp;show-faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;locale=es_LA' frameborder='0' scrolling='no' style='vertical-align: middle; border: medium none; overflow: hidden; width: 100px; height: 21px;' allowtransparency='true'></iframe></div>";
		$addthis = '<div class="addthis_toolbox fb_like">'.
                  		'<div class="hover_effect">'.
							'<div style="display:inline-block"><a class="addthis_button_twitter"'.
		                  		'addthis:url="http://'.$url.'"'.
	                  	        'addthis:title="'.$marker_name.' en '.$marker["address"].' #'.str_replace(" ","", $marker["city"]).' @conocepunta">&nbsp;</a></div>'.                  	                     	
                  	        '<div style="display:inline-block"><a class="addthis_button_google"'.
                  	        	'addthis:url="http://'.$url.'"'.
                  	            'addthis:title="'.$marker_name.': '.$marker["address"].' @conocepunta">&nbsp;</a></div>'.
                  	        '<div style="display:inline-block"><a class="addthis_button_expanded">&nbsp;&nbsp;Mas</a></div>'.
                  	        '<div style="clear:both; float:none;"></div>'.
                  	    '</div>'.
                  	 '</div>';		  		 
		//$gplusbutton = '<g:plusone size="small" href="http://'.$url.'"></g:plusone>';
		 
		$social = "<div>".$fb.$addthis."</div>";
		//--------------------------------
	
		//$image = "<figure><img alt='".$marker_name."' class='lheader' src='".$marker['img']."'></figure>";
		//---------------static map
		//$image = "<figure><img alt='".$marker_name."' class='lheader' src='http://maps.google.com/staticmap?center=".$marker['lat'].",".$marker['lng']."&zoom=15&size=225x225&maptype=satellite&&markers=icon:".$marker['icon']."%7C".$marker['lat'].",".$marker['lng']."&key=ABQIAAAALyKwFZzMQBTWU3CUmBrN7RTvufBQ4WA-npmjEqhq0GDcUkCFMRTabPeW_m0vIN3Bghd4m7Mv_m-mOQ'></figure>".
		$image = "<figure><img alt='".$marker_name."' class='lheader' src='http://maps.google.com/staticmap?center=".$marker['lat'].",".$marker['lng']."&zoom=15&size=225x225&maptype=satellite&&markers=".$marker['lat'].",".$marker['lng']."&key=ABQIAAAALyKwFZzMQBTWU3CUmBrN7RTvufBQ4WA-npmjEqhq0GDcUkCFMRTabPeW_m0vIN3Bghd4m7Mv_m-mOQ'></figure>";
		//-------------------------		
		
		$desc = "<p>".$marker['description']."</p>";
		//$screen = "<div class='screenshot vintage lheader' style='margin-bottom:7px'>".
		$screen = "<div class='vintage lheader' style='margin-bottom:7px'>".
						$image.		
                  "</div>".
        		  "<div class='figcaption'>".
						//str_pad(substr($marker_name,0,15),18,"...").
						//$marker_name.
						"<p>".$marker['address']."</p>".
						"<p class='place'>".$marker['city']."</p>".
				  "</div>".
				  $social;
		//----------------------------------------------------------------------
		//loading related data
		$related = "<ul>";
		foreach ($marker['related'] as $k => $rel){
			$clean_name = str_replace("-", " ", $rel['name']);
			$related .= "<li class='box mini-post'>
							<figure><img class='small' title='".$clean_name."' alt='".$clean_name."' src='".$rel['img']."'></figure>
							<a href='".base_url().$this->category_string($rel['marker_cat'])."/nombre/".$rel['name']."' target='_new'>".$clean_name."</a>
						</li>";
		}
		$related .= "</ul>";
		
		$content =  "<div class='brief box post'>".
					//title
					"<div>".
						//"<p class='place'>$marker_name</p>".
						//"<h1>".$marker_name." ".$deturno_html."</h1>".
						"<h1>".$marker_name."</h1>".
						//"<p class='place'>$date</p>".
						//"<p class='place'>".$marker['city'].": ".$marker['address']."</p>".
					"</div>".
					"<p class='separator'></p>".
					//------					
					"<article id='".$marker['name']."' class='inline box post lheader'>".
						$screen.
					"</article>".
					"<article class='inline' style='padding-left: 20px; max-width: 500px;'>".
						"<div>".
							//"<p class='place'>$date</p>".
							//"<p class='place'>".$marker['city'].": ".$marker['address']."</p>".
							$desc.
							//$social.
						"</div>".
					"</article>".
					//"<p class='separator'></p>".
					"<article class='inline figcaption' style='width:100%'>".
						"<p class='separator'></p>".
						"<p class='place' style='text-align:left; padding-bottom:10px'>Entradas relacionadas...</p>".
						$related.
					"</article>".		
					"</div>";
		return $content;
	}
		
	/**
	 * 
	 * Defines a navigation bar with the JQuery tab style 
	 * @return string: navigation bar
	 */
	function write_navbar(){
		$bar =	"<div id='navbar' class='ui-tabs content centered ui-widget ui-widget-content ui-corner-all'>".
	    			      	"<ul class='ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all'>".
	          					"<li class='ui-state-default ui-corner-top'>".
	                				"<a href='http://www.conocepunta.com.ar' class='inicio'>Inicio</a>".
	                			"</li>".		
								"<li class='ui-state-default ui-corner-top'>".
			                		"<a href='http://www.conocepunta.com.ar/salidas' class='salidas'>Salidas</a>".
			                	"</li>".		                					      	
	    			            "<li class='ui-state-default ui-corner-top'>".
	    			      			"<a href='http://www.conocepunta.com.ar/eventos' class='eventos'>Eventos</a>".
	    			      		"</li>".		      		
	    			      		"<li class='ui-state-default ui-corner-top'>".
	    			      			"<a href='http://www.conocepunta.com.ar/plazas' class='plazas'>Plazas</a>".
	    			      		"</li>".
	    			      		"<li class='ui-state-default ui-corner-top'>".
	    			      			"<a href='http://www.conocepunta.com.ar/negocios' class='negocios'>Negocios</a>".
	    			      		"</li>".
	    			      		"<li class='ui-state-default ui-corner-top'>".
	    			      			"<a href='http://www.conocepunta.com.ar/interes' class='interes'>Interes</a>".
	    			      		"</li>".
	    			      		"<li class='ui-state-default ui-corner-top'>".
	    			      			 "<a href='http://www.conocepunta.com.ar/deporte' class='deporte'>Deporte</a>".
	    			      		"</li>".
	    			      		"<li class='ui-state-default ui-corner-top'>".
	    			      		"<a href='http://www.conocepunta.com.ar/farmacias' class='farmacias'>Farmacias</a>".
	    			      		"</li>".	    			      		
								"<li class='ui-state-default ui-corner-top'>".
	    			      			 "<a href='http://www.conocepunta.com.ar/contacto' class='contacto'>Contacto</a>".
	    			      		"</li>".	    		    			      		   		
	    			      		"<li class='ui-state-default ui-corner-top'>".
	    			      			"<a href='http://www.conocepunta.com.ar/socios' class='socios'>Asociate</a>".
	    			      		"</li>".
	    			      	"</ul>".
	    			     "</div>".
	    			"<script>".
					//setting selected tab
	    			"$('.".$this->get_controller_name()."').parent().addClass('ui-tabs-selected ui-state-active');".
					//setting hover effect to the navigation bar items
	    			"$('.ui-tabs-nav > li').hover(function(){
	    					$(this).addClass('ui-state-hover');
	    				},function(){
	    					$(this).removeClass('ui-state-hover');						
	    				});".				      	          
	    	      	"</script>";    	
		return $bar;
	}
	
	function write_map($draggable = 'false'){		
		//---------MAP---------
		$map = "<div id='map' title='Mapa de Punta Alta'></div>";
		//setting dialog map
		$map .= "<script type='text/javascript'>".
		        				      "$('#map').dialog({
		        				      	autoOpen: false,
		        				      	width: 550,
		        				      	height: 400,
		        				      	modal:true,
		        				      	resizable:true,
		        				      	draggable:false
		        				      });".				      
		              			 "</script>";
		//---------------------
		return $map;		
	}
	
	function category_string($cat){
	  	$query = $this->db->query("SELECT name
						  			FROM categoria
						  			WHERE id_categoria = $cat
					  			");
	  	//$row = $query->row();
	  	$row = $query->row_array();
	  	return $row['name'];
	}
}	
// END _Controller class

/* End of file Controller.php */
/* Location: ./system/libraries/Controller.php */